# coding:utf-8
import string
import random
phone_prefix = ["133", "149", "153", "173", "177", "180", "181", "189", "190", "191", "193", "199", "130", "131", "132", "145", "155", "156", "166", "167", "171", "175", "176", "185", "186", "196", "134", "135", "136", "137", "138", "139", "144", "147", "148", "150", "151", "152", "157", "158", "159", "172", "178", "182", "183", "184", "187", "188", "195", "197", "198", "170", "174"]


def get_password():
    """
    获取密码：
    列表中先插入长度减3的字符，再随机插入一个大写、小写和_
    """
    length = random.randint(8, 16)
    all_content = string.ascii_letters + string.digits
    list_password = random.choices(all_content, k=length-3)
    list_password.insert(random.randint(0, len(list_password)), random.choice(string.ascii_uppercase))
    list_password.insert(random.randint(0, len(list_password)), random.choice(string.ascii_lowercase))
    list_password.insert(random.randint(0, len(list_password)), '_')
    return "".join(list_password)


def get_phone():
    """
    获取手机号：
    生成手机开头和手机号结尾，拼接
    假设有后8位00000000的手机号
    """
    phone_head = random.choice(phone_prefix)
    phone_end = ""
    for num in range(8):
        phone_end += str(random.randint(0, 9))
    return phone_head + phone_end


def get_phone_and_password(number):
    """生成不重复的手机号和密码列表"""
    phone_pwd_list = []
    while True:
        phone = get_phone()
        password = get_password()
        for phone_pwd in phone_pwd_list:
            if phone == phone_pwd.get('phone') or password == phone_pwd.get('password'):
                break
        else:
            phone_pwd_list.append({'phone': phone, 'password': password})
            if len(phone_pwd_list) >= number:
                return phone_pwd_list


if __name__ == '__main__':
    test = get_phone_and_password(5)
    print(test)


